package java_thinking.unit_17;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @Desc:   LRUCache
 * @author: cww
 * @DateTime: 2020-03-28 9:29
 */

public class LRUCache1 extends LinkedHashMap<Integer,Integer> {
    private int capacity;
    public LRUCache1(int capacity) {
        super(capacity, 0.75F, true);
    }

    public int get(int key){
        return super.getOrDefault(key,-1);
    }

    public void set(int key,int value){
        super.put(key,value);
    }

    @Override
    protected boolean removeEldestEntry(Map.Entry<Integer,Integer> map){
        return size()>capacity;
    }

}

